* Table C2: Realized and benchmark assignments

********************************************************************************
************************** Prepare data ****************************************
********************************************************************************

clear all
use contract_id_real contract_id_orig funding_real funding_orig using "${data_matchings}", clear

********************************************************************************
************************** Prepare table ***************************************
********************************************************************************

cap file close sumstat
file open sumstat using "${tableC2}", write replace
file write sumstat "\begin{tabular}{l c c} \\ \hline\hline" _n
file write sumstat " & Realized & \multicolumn{1}{c}{Benchmark} \\ " _n
file write sumstat " & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)}  \\ \hline" _n
	* Number of students assigned ----------------------------------------------
	qui: count if contract_id_real != .
	local real_count: display %12.0fc r(N)
	
	qui: count if contract_id_orig != .
	local benchmark_sr_count: display %12.0fc r(N)
	
	file write sumstat "Assigned to a contract & `real_count' & `benchmark_sr_count' \\ " _n

	* Assigned to a stat-funded contract ---------------------------------------
	qui: count if contract_id_real != . & funding_real == 1
	local real_count: display %12.0fc r(N)
	
	qui: count if contract_id_orig != . & funding_orig == 1
	local benchmark_sr_count: display %12.0fc r(N)
		
	file write sumstat "Assigned to a state-funded contract & `real_count' & `benchmark_sr_count'  \\  " _n
	
	* Assigned to self-funded contract -----------------------------------------
	qui: count if contract_id_real != . & funding_real == 2
	local real_count: display %12.0fc r(N)
	
	qui: count if contract_id_orig != . & funding_orig == 2
	local benchmark_sr_count: display %12.0fc r(N)
		
	file write sumstat "Assigned to a self-funded contract & `real_count' & `benchmark_sr_count'  \\ \hline\hline" _n
	file write sumstat "\multicolumn{3}{p{10.5cm}}{{\it Notes}: The table presents the number of applicants assigned under each of the financial terms in the realized assignment in 2007 (column (1)) and in our benchmark assignment (column (2)).} \\ " _n
file write sumstat "\end{tabular}" _n
file close sumstat
